package com.ruoyi.web.pojo.vo.devicedata;

import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.utils.CommonUtils;
import com.ruoyi.web.domain.devicedata.DevicePhoto;
import com.ruoyi.web.domain.insect.InsectRecord;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.collections.CollectionUtils;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * @author yaojianbo
 * @description 设备图片出参
 * @date 2023/2/20 16:35
 */
@Data
@ApiModel("设备图片")
public class DevicePhotoVO {

    @ApiModelProperty(value = "设备id")
    @Excel(name = "设备编号",  lineMergeId = true,lineMerge = true , sort = 2)
    private String deviceId;

    @ApiModelProperty(value = "设备名称")
    private String deviceName;

    @ApiModelProperty(value = "设备图片id")
    private Long attachmentId;

    @ApiModelProperty(value = "图片地址")
    @Excel(name = "图片地址", sort = 3 , width = 72)
    private String picUrl;

    @ApiModelProperty(value = "预置点名称")
    @TableField("preset_name")
    private String presetName;

    @ApiModelProperty(value = "预置点名称")
    @TableField("description")
    private String description;

    @ApiModelProperty(value = "图片时间")
    @JsonFormat (pattern ="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    @Excel(name = "图片时间", sort = 4 , dateFormat = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime picTime;

    @ApiModelProperty(value = "识别数量")
//    @Excel(name = "识别数量", sort = 5)
    private Integer count = 0;

    @ApiModelProperty(value = "种类数量")
    private Integer types = 0;

    @ApiModelProperty(value = "识别")
    private List<InsectRecord> insectRecord = new ArrayList<>();

    public DevicePhotoVO() {

    }

    public DevicePhotoVO(DevicePhoto photo, List<InsectRecord> insectRecord ) {
        this.picUrl = CommonUtils.generateAbsoluteUrl(photo.getPicUrl());
        this.deviceId = photo.getDeviceId();
        this.picTime = photo.getCrtTime();
        this.attachmentId = photo.getAttachmentId();
        this.description = photo.getDescription();
        this.presetName = photo.getPresetName();

        if(CollectionUtils.isEmpty(insectRecord)){
           return;
        }

        this.insectRecord = insectRecord;
        this.count = insectRecord.stream().mapToInt(InsectRecord::getCount).sum();
    }
}
